<?php


class DbTable_Mercado extends Zend_Db_Table_Abstract
{
    protected $_name = 't_mercado';
    protected $_rowClass = 'Mercado';
    protected $_primary = 'id_mercado';
    
    protected $_dependentTables = array('DbTable_MercadoPreferido');
    
    
    protected $_referenceMap    = array(
        	'DbTable_RedeMercado' => array(
	            'columns'           => array('id_rede_mercado'), //FK
	            'refTableClass'     => 'DbTable_RedeMercado',
	            'refColumns'        => array('id_rede_mercado')),
    		'DbTable_Endereco' => array(
    				'columns'           => array('id_endereco'), //FK
    				'refTableClass'     => 'DbTable_Endereco',
    				'refColumns'        => array('id_endereco')),
                'DbTable_Coordenada' => array(
    				'columns'           => array('id_coordenada'), //FK
    				'refTableClass'     => 'DbTable_Coordenada',
    				'refColumns'        => array('id_coordenada'))
	);
    
    
    public static function buscarMercadoPorId($id){
    	$tMercado = new DbTable_Mercado();
    	
    	return $tMercado->find($id)->current();
    }
    
    
    public static function hasMercado($nomeMercado){
    	$tMercado = new DbTable_Mercado();
    	 
    	$mercados = $tMercado->fetchAll(array('nm_mercado = (?)' => strtoupper($nomeMercado)));
    	 
    	return count($mercados) > 0;
    }
    
    
}